home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl70b2.lha / tcl7.0b2 / tests / rename.test < prev    next >
Text File  |  1993-02-06  |  3KB  |  79 lines

  1. # Commands covered:  rename
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # All rights reserved.
  9. #
  10. # Permission is hereby granted, without written agreement and without
  11. # license or royalty fees, to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose, provided that the
  13. # above copyright notice and the following two paragraphs appear in
  14. # all copies of this software.
  15. #
  16. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  17. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  18. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  19. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. #
  21. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  22. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  24. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  25. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  26. #
  27. # $Header: /user6/ouster/tcl/tests/RCS/rename.test,v 1.5 93/02/06 15:54:23 ouster Exp $ (Berkeley)
  28.  
  29. if {[string compare test [info procs test]] == 1} then {source defs}
  30.  
  31. catch {rename r2 {}}
  32. proc r1 {} {return "procedure r1"}
  33. rename r1 r2
  34. test rename-1.1 {simple renaming} {
  35.     r2
  36. } {procedure r1}
  37. test rename-1.2 {simple renaming} {
  38.     list [catch r1 msg] $msg
  39. } {1 {invalid command name: "r1"}}
  40. rename r2 {}
  41. test rename-1.3 {simple renaming} {
  42.     list [catch r2 msg] $msg
  43. } {1 {invalid command name: "r2"}}
  44.  
  45. # The test below is tricky because it renames a built-in command.
  46. # It's possible that the test procedure uses this command, so must
  47. # restore the command before calling test again.
  48.  
  49. rename list l.new
  50. set a [catch list msg1]
  51. set b [l.new a b c]
  52. rename l.new list
  53. set c [catch l.new msg2]
  54. set d [list 111 222]
  55. test 2.1 {renaming built-in command} {
  56.     list $a $msg1 $b $c $msg2 $d
  57. } {1 {invalid command name: "list"} {a b c} 1 {invalid command name: "l.new"} {111 222}}
  58.  
  59. test rename-3.1 {error conditions} {
  60.     list [catch {rename r1} msg] $msg $errorCode
  61. } {1 {wrong # args: should be "rename oldName newName"} NONE}
  62. test rename-3.2 {error conditions} {
  63.     list [catch {rename r1 r2 r3} msg] $msg $errorCode
  64. } {1 {wrong # args: should be "rename oldName newName"} NONE}
  65. test rename-3.3 {error conditions} {
  66.     proc r1 {} {}
  67.     proc r2 {} {}
  68.     list [catch {rename r1 r2} msg] $msg
  69. } {1 {can't rename to "r2": command already exists}}
  70. test rename-3.4 {error conditions} {
  71.     catch {rename r1 {}}
  72.     catch {rename r2 {}}
  73.     list [catch {rename r1 r2} msg] $msg
  74. } {1 {can't rename "r1":  command doesn't exist}}
  75. test rename-3.5 {error conditions} {
  76.     catch {rename _non_existent_command {}}
  77.     list [catch {rename _non_existent_command {}} msg] $msg
  78. } {1 {can't delete "_non_existent_command": command doesn't exist}}
  79.